import { load, getTimestamp } from '@/utils'

const module = {
  namespaced: true,
  state: {
    film: null
  },
  mutations: {
    setFilm (state, film) {
      state.film = film
    }
  },
  actions: {
    getFilm (store, obj) {
      load({
        url: `/gateway?filmId=${obj.filmId}&k=${getTimestamp()}`,
        headers: { 'X-Host': 'mall.film-ticket.film.info' }
      }).then(res => {
        store.commit('setFilm', res.data.data.film)
      }).catch((err) => {
        console.warn(err)
        store.commit('setFilm', null)
      })
    }
  }
}

export default module
